<%@ taglib prefix="c"   uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib uri="http://micronova.com/yuzu" prefix="m"%> 
<%@page import = "com.db4o.ext.ExtObjectContainer" %>
<%@page import = "com.db4o.servlet.Db4oServlet" %>
<%@page import = "facades.*" %>
<%@page import = "auser.*" %>
<%@page import = "java.util.*" %>
<%  SessionFacade sfacade = new SessionFacade(session); %>
<jsp:useBean id="editTessera" scope="session" class="auser.Tessera" />
<%  sfacade.setSessionBean("editTessera",request.getParameterMap()); %>
<%  Tessera tes = (Tessera) session.getAttribute("editTessera"); %>

<c:set var='valid' value='${true}' scope="request" />

<c:if test="${empty param.idsocio && param.editMode=='ADD'}">
	<%   tes.setSocio(null); %>
	<c:set var='eSocio' value='necessario'  scope='request'/>
	<c:set var='valid' value='${false}' />
</c:if>

<c:if test="${empty editTessera.annoCompetenza || editTessera.annoCompetenza==0}">
	<c:set var='eAnnoCompetenza' value='necessario'  scope='request'/>
	<c:set var='valid' value='${false}' />
</c:if>

<c:if test="${empty editTessera.numeroTessera || editTessera.numeroTessera==0}">
	<c:set var='eNumeroTessera' value='necessario'  scope='request'/>
	<c:set var='valid' value='${false}' />
</c:if>
 
<%  Socio socioTessera = null; %>
<c:if test="${param.editMode=='ADD' && !empty param.idsocio}">
	<%  String idsocio = request.getParameter("idsocio"); %> 
	<%  socioTessera = (Socio)sfacade.getById(idsocio); %>
	<jsp:setProperty name="editTessera"  value="<%=socioTessera %>" property="socio"/>	
	<c:set var='eDebug' value=' '  scope='request'/>
</c:if>

<c:if test="${valid}">
	
	<c:if test="${param.editMode=='ADD'}">
		<%   socioTessera.setUltimaTessera(tes.getAnnoCompetenza() ,tes.getNumeroTessera()); %> 
		<%   sfacade.saveScritturaSoci(tes);   %> 
	</c:if>
		
	<% sfacade.setFromSession("editTessera",true); %> 
	<c:redirect url="/app/start/index.jsp" />
</c:if>


<c:if test="${!valid}">
	<jsp:forward page="edit.jsp" />
</c:if>